home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: ostrstream: Who knows it exectly?
- Date: 30 Jan 1996 18:57:19 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan30135719@g7240065.bridge.bst.bls.com>
- References: <4el56r$357@fsuj01.rz.uni-jena.de>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: mkt@isun04.inf.uni-jena.de's message of 30 Jan 1996 13:07:39 GMT
-
- In article <4el56r$357@fsuj01.rz.uni-jena.de> mkt@isun04.inf.uni-jena.de (Tilo Koerbs) writes:
-
- : Look at this piece of code:
-
- : ostrstream buf; // dynamic buffer.
- : // Fill buf...
- : buf << ends; // Append NULL-byte.
- : char *p = buf.str(); // Freeze buffer.
-
- : And now the problem: The users must delete the buffer
- : by there own. But HOW???
- : This way: delete p;
- : Or this way: delete [] p;
-
- : Different books give different answers!
- : Is it implementation dependend? (I don't think so!)
- : Or can I do both? (I don't think so too!)
-
- You must use:
- delete[] p;
-
- buf.str() returns a pointer to the array being used. Using delete and not
- delete[] on that array leads to undefined behaviour.
-
- 5.3.5 Delete
- ...
- 2 In either alternative, if the value of the operand of the delete is the
- null pointer the operation has no effect. Otherwise, in the first
- alternative (delete object), the value of the operand of the delete shall
- be a pointer to a non-array object created by [valid creations deleted for
- brevity...]. If not the behaviour is undefinded. In the second alternative
- (delete[] array), the value of the operand of the deletee shall be a pointer
- to an array created by a new-expression without a new-placement
- specification. If not, the behaviour is underfined.
-
- Regards
-
- -A.
- --
- | A.Champion |
-